// DBOptEDASex.cpp: implementation of the CDBOptEDASex class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "DBOptEDASex.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CDBOptEDASex::CDBOptEDASex()
{
	int iRetLen= GetSystemDirectory( _storage._strIniFilePath.GetBuffer( MAX_PATH ), MAX_PATH );
	if (iRetLen > MAX_PATH)
	{
		GetSystemDirectory( _storage._strIniFilePath.GetBuffer( iRetLen ), iRetLen );
	}
	_storage._strIniFilePath.ReleaseBuffer();
	_storage._strIniFilePath += "\\eDASexpress.ini";
}

CDBOptEDASex::~CDBOptEDASex()
{

}

BOOL CDBOptEDASex::LoadOptions()
{
	if (FALSE == CDBOptions<CIniFile>::LoadOptions())
		return FALSE;

// 	HKEY hEDASexDbOption;
// 	LONG retOpenReg= RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\Chiciton\\eDASex\\DataBase", NULL, KEY_READ, &hEDASexDbOption);
// 	if (ERROR_SUCCESS != retOpenReg)
// 		return FALSE;
// 
//     TCHAR    achKey[MAX_PATH];   // buffer for subkey name
//     DWORD    cbName;                   // size of name string 
//     TCHAR    achClass[MAX_PATH] = TEXT("");  // buffer for class name 
//     DWORD    cchClassName = MAX_PATH;  // size of class string 
//     DWORD    cSubKeys=0;               // number of subkeys 
//     DWORD    cbMaxSubKey;              // longest subkey size 
//     DWORD    cchMaxClass;              // longest class string 
//     DWORD    cValues;              // number of values for key 
//     DWORD    cchMaxValue;          // longest value name 
//     DWORD    cbMaxValueData;       // longest value data 
//     DWORD    cbSecurityDescriptor; // size of security descriptor 
// 	FILETIME ftLastWriteTime;      // last write time 
//     // Get the class name and the value count. 
//     DWORD retCode = RegQueryInfoKey(
// 						hEDASexDbOption,		// key handle 
// 						achClass,                // buffer for class name 
// 						&cchClassName,           // size of class string 
// 						NULL,                    // reserved 
// 						&cSubKeys,               // number of subkeys 
// 						&cbMaxSubKey,            // longest subkey size 
// 						&cchMaxClass,            // longest class string 
// 						&cValues,                // number of values for this key 
// 						&cchMaxValue,            // longest value name 
// 						&cbMaxValueData,         // longest value data 
// 						&cbSecurityDescriptor,   // security descriptor 
// 						&ftLastWriteTime);       // last write time 
// 	
//     // Enumerate the subkeys, until RegEnumKeyEx fails.
// 
// 	char *pszValue= new char[cchMaxValue];
// 	BYTE *pbyValueData= new BYTE[cbMaxValueData];
//     for (DWORD i= 0; i < cValues; i++) 
//     { 
// 		DWORD dwType;
// 		DWORD cchValue= cchMaxValue;
// 		DWORD cbValueData= cbMaxValueData;
// 		memset(pszValue, 0, cchMaxValue);
// 		memset(pbyValueData, 0, cbMaxValueData);
//         cbName = MAX_PATH;
//         retCode = RegEnumValue(hEDASexDbOption, i,
// 			pszValue,
// 			&cchValue,
// 			NULL, 
// 			&dwType,
// 			pbyValueData,
// 			&cbValueData); 
//         if (retCode == ERROR_SUCCESS) 
//         {
//             _tprintf(TEXT("(%d) %s\n"), i+1, achKey);
//         }
//     }
// 	delete [] pszValue;
// 	delete [] pbyValueData;

	BOOL ret= TRUE;

	if (FALSE == _storage.LoadOptions("Server", "(local)", _pszSqlServer))
		ret = FALSE;
	if (FALSE == _storage.LoadOptions("DB", "eDASexpress", _pszDatabaseName))
		ret = FALSE;
	if (FALSE == _storage.LoadOptions("Flag", "0", _dwAuthMode))
		ret = FALSE;
	if (FALSE == _storage.LoadOptions("User", "sa", _pszUserName))
		ret = FALSE;
	if (FALSE == _storage.LoadOptions("Pwd", "", _pszPassword))
		ret = FALSE;

	if (TRUE == ret)
		_isLoaded = TRUE;

	return ret;
}
